package com;

/**
 * Created by Administrator on 2016/1/27.
 */

import java.io.FileWriter;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class XMLWriterTest {
    /**
     * @param args
     * @throws IOException
     * @author Young
     */
    public static void main(String[] args) throws IOException {
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(new FileWriter("output.xml"), format);
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("root").addAttribute("receiveTime","20150126");
        //root.addComment("This is xml comment");
       /* root.addElement("author").addAttribute("name", "James")
                .addAttribute("location", "UK").addText("James Strachan");*/
        root.addElement("content").addText("你是觉得好");
        root.addElement("content1").addText("你是觉得好");
        root.addElement("content2").addText("你是觉得好");
        String s = document.asXML();
        System.out.println(document.asXML());
        writer.write(document);
        writer.close();
    }
}
